! RIM USB IP Modem
!
! Copyright:	 2009 Research In Motion Ltd., All Rights Reserved.
!
! Use this script when you have a Black Berry connected by USB or Bluetooth
!

@ORIGINATE
serreset 115200, 0, 8, 1 
hsreset 0 0 0 0 0 0
settries 0
jump 1

@ANSWER
exit -6025

@HANGUP
write "ATH\13"
pause 15
write "AT+MACMODE=0\13"
pause 15
hsreset 0 0 0 0 0 0
exit 0

@LABEL 1
flush
matchclr
matchstr 1 2 "OK\13\10"
matchstr 2 13 "ERROR\13\10"
write "ATE0V1\13\10"
matchread 30
inctries
iftries 20 13
jump 1

@LABEL 2
pause 5
flush
matchclr
matchstr 1 3 "OK\13\10"
matchstr 2 13 "ERROR\13\10"
write "AT\13"
matchread 30

@LABEL 3
matchclr
matchstr 1 4 "OK\13\10"
matchstr 2 13 "ERROR\13\10"
write "ATS0=0\13"
matchread 30

@LABEL 4
matchclr
matchstr 1 5 "OK\13\10"
matchstr 2 13 "ERROR\13\10"
write "AT\13"
matchread 30
settries 0

@LABEL 5
ifstr 28 6 ""
matchclr
matchstr 1 6 "OK\13\10"
matchstr 2 6 "ERROR\13\10"

write "^28^23,\34IP\34,\34^22\34\13"
matchread 30

@LABEL 6
matchclr
matchstr 1 7 "OK\13\10"
matchstr 2 7 "ERROR\13\10"

write "AT+MACMODE=1\13"
matchread 30

@LABEL 7

ifstr 1 8 ""

matchclr
matchstr 1 22 "CONNECT\13\10"
matchstr 2 27 "NO CARRIER\13\10"
matchstr 3 13 "ERROR\13\10"
matchstr 4 13 "0\13\10"
matchstr 5 13 "NO DIALTONE\13\10"
matchstr 6 13 "BUSY\13\10"
matchstr 8 13 "NO ANSWER\13\10"
matchstr 9 13 "HAND SET IN USE\13\10"

write "ATD^1\13"
matchread 80
jump 27


@LABEL 8
matchclr
matchstr 1 11 "0\13\10"
matchstr 2 11 "ERROR\13\10"
matchstr 3 9 "1\13\10"
matchstr 4 9 "2\13\10"
matchstr 5 9 "3\13\10"
matchstr 6 10 "4\13\10"

write "AT+NT\13"
matchread 30


@LABEL 9
matchclr
matchstr 1 22 "CONNECT\13\10"
matchstr 2 29 "NO CARRIER\13\10"
matchstr 3 13 "ERROR\13\10"
matchstr 4 13 "0\13\10"
matchstr 5 13 "NO DIALTONE\13\10"
matchstr 6 13 "BUSY\13\10"
matchstr 7 13 "NO ANSWER\13\10"
matchstr 8 13 "HAND SET IN USE\13\10"

write "ATD#777\13"
matchread 80
jump 29


@LABEL 10
matchclr
matchstr 1 22 "CONNECT\13\10"
matchstr 2 30 "NO CARRIER\13\10"
matchstr 3 13 "ERROR\13\10"
matchstr 4 13 "0\13\10"
matchstr 5 13 "NO DIALTONE\13\10"
matchstr 6 13 "BUSY\13\10"
matchstr 7 13 "NO ANSWER\13\10"
matchstr 8 13 "HAND SET IN USE\13\10"

write "ATD*99#\13"
matchread 80
jump 30

@LABEL 11
matchclr
matchstr 1 21 "ERROR\13\10"
matchstr 2 9 "+GCAP: +CIS707"
matchstr 3 10 "+GCAP: +CGSM"

write "AT+GCAP\13"
matchread 30
jump 21


@LABEL 21
matchclr
matchstr 1 22 "CONNECT\13\10"
matchstr 2 31 "NO CARRIER\13\10"
matchstr 3 13 "ERROR\13\10"
matchstr 4 13 "0\13\10"
matchstr 5 13 "NO DIALTONE\13\10"
matchstr 6 13 "BUSY\13\10"
matchstr 7 13 "NO ANSWER\13\10"
matchstr 8 13 "HAND SET IN USE\13\10"
write "ATD^27\13"
matchread 80
jump 31


@LABEL 22
note "BlackBerry IP Modem Connected"
hsreset 0 1 0 0 0 0
!  Success
pause 15
exit 0

@LABEL 13
note "Modem error; the modem is not responding." 3
exit -6019

@LABEL 27
inctries
iftries 5 13
pause 5
jump 7

@LABEL 29
inctries
iftries 5 13
pause 5
jump 9

@LABEL 30
inctries
iftries 5 13
pause 5
jump 10

@LABEL 31
inctries
iftries 5 13
pause 5
jump 21



